/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.proyecto;

import com.proyecto.datos.EntityCatedratico;
import com.proyecto.datos.EntityGrupo;
import com.proyecto.datos.EntityHorario;
import com.proyecto.datos.EntityHorarioLab;
import com.proyecto.datos.EntityMateria;
import com.proyecto.datos.EntityPlan;
import com.proyecto.modelado.Catedratico;
import com.proyecto.modelado.DetalleHorarioLab;
import com.proyecto.modelado.DetalleHorarioMateria;
import com.proyecto.modelado.Grupo;
import com.proyecto.modelado.Horario;
import com.proyecto.modelado.Materia;
import com.proyecto.modelado.Plan;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author mario
 */
public class frmMantenimientoGrupoLaboratorio extends javax.swing.JInternalFrame {

    Materia mate;
    Horario hora;
    Catedratico cate;
    Grupo grupo;
    DetalleHorarioLab detahorlab;
    EntityMateria entMate;
    EntityHorario entHora;
    EntityCatedratico entCate;
    EntityGrupo entGrupo;
    ArrayList arryTable;
    int id_materia;
    int id_horario;
    int id_catedratico;
    int id_grupo;
    int id_materia1;
    int id_materia2;
    int id_plan;
    int id_plan2;
    Plan pla;
    EntityPlan entPla;
    
    
    
     public void CargarComboBoxMateria(int id_plan) {
        //CARGANDO COMBOBOX DE MATERIAS
        ArrayList arryRad = new ArrayList();


        mate = new Materia();
        arryRad = mate.MostrarMateriasPlan_U1(id_plan);
        JList list_rad = new JList();
        DefaultListModel listModel_rad = new DefaultListModel();
        listModel_rad.addElement("Seleccione");
        if (arryRad != null) {
            for (int i = 0; i < arryRad.size(); i++) {
                entMate = (EntityMateria) arryRad.get(i);
                listModel_rad.addElement(entMate.getCodigo_asignatura());
            }
        } else {
            JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la tabla Materia", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
        }
        list_rad.setModel(listModel_rad);
        this.jcmbMateria.setModel(new DefaultComboBoxModel(listModel_rad.toArray()));
        this.jcmbMateria.setSelectedIndex(0);
    }
    
    
    public void CargarComboBoxMateria2(int id_plan2) {
        //CARGANDO COMBOBOX DE MATERIAS
        ArrayList arryRad = new ArrayList();
       
        
        mate= new Materia();
        arryRad = mate.MostrarMateriasPlan_U1(id_plan2);
        JList list_rad = new JList();
        DefaultListModel listModel_rad = new DefaultListModel();
        listModel_rad.addElement("Seleccione");
        if (arryRad != null) {
            for (int i = 0; i < arryRad.size(); i++) {
                entMate = (EntityMateria) arryRad.get(i);
                listModel_rad.addElement(entMate.getCodigo_asignatura());
            }
        } else {
            JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la tabla Materia", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
        }
        list_rad.setModel(listModel_rad);
        this.jcmbMateria2.setModel(new DefaultComboBoxModel(listModel_rad.toArray()));
        this.jcmbMateria2.setSelectedIndex(0);
    }

    public void cargarComboboxPlan() {

        ArrayList arryPlan = new ArrayList();
        pla = new Plan();
        arryPlan = pla.MostrarPlan();
        JList list_rad = new JList();
        DefaultListModel listModel_rad = new DefaultListModel();

        listModel_rad.addElement("Seleccione");
        if (arryPlan != null) {
            for (int i = 0; i < arryPlan.size(); i++) {
                entPla = (EntityPlan) arryPlan.get(i);
                listModel_rad.addElement(entPla.getNombre_plan());
            }
        } else {
            JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la tabla Materia", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
        }
        list_rad.setModel(listModel_rad);

        //seteando dos combos con los planes

        this.jcmbPlan.setModel(new DefaultComboBoxModel(listModel_rad.toArray()));
        this.jcmbPlan.setSelectedIndex(0);

        this.jcmbPlan2.setModel(new DefaultComboBoxModel(listModel_rad.toArray()));
        this.jcmbPlan2.setSelectedIndex(0);


    }
    

    public void PopulatTabla() {

        DefaultTableModel tabla;
        Object[] fila = new Object[6];

        try {
            String[] columnName = {"ID", "Materia", "Horario", "Instructor", "Grupo de Laboratorio", "Cupo"};
            tabla = new DefaultTableModel(null, columnName);
            //populamos el arraylist de la tabla
            arryTable = new ArrayList();
            detahorlab = new DetalleHorarioLab();
            EntityHorarioLab entHorLab = new EntityHorarioLab();
            arryTable = detahorlab.MostrarCatalogoGruposLaboratorio();
            if (arryTable != null) {
                for (int i = 0; i < arryTable.size(); i++) {
                    entHorLab = (EntityHorarioLab) arryTable.get(i);
                    fila[0] = entHorLab.getId();
                    fila[1] = entHorLab.getEntMateria();
                    fila[2] = entHorLab.getEntHorario();
                    fila[3] = entHorLab.getEntCatedratico().concat(" ").concat(entHorLab.getEntCatedraticoApellido());
                    fila[4] = entHorLab.getEntGrupo();
                    fila[5] = entHorLab.getCupo();
                    tabla.addRow(fila);
                }
                this.jtbleGrupos.setModel(tabla);
            } else {
                JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la base de datos", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex.toString());
        }
    }

//    public void CargarComboBox10() {
//
//        ArrayList arryRad = new ArrayList();
//        mate = new Materia();
//        arryRad = mate.MostrarMateriasPlan10();
//        JList list_rad = new JList();
//        DefaultListModel listModel_rad = new DefaultListModel();
//        listModel_rad.addElement("Seleccione");
//        if (arryRad != null) {
//            for (int i = 0; i < arryRad.size(); i++) {
//                entMate = (EntityMateria) arryRad.get(i);
//                listModel_rad.addElement(entMate.getCodigo_asignatura());
//            }
//        } else {
//            JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la tabla Materia", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
//        }
//        list_rad.setModel(listModel_rad);
//        this.jcmbMateria.setModel(new DefaultComboBoxModel(listModel_rad.toArray()));
//        this.jcmbMateria.setSelectedIndex(0);
//
//    }
//
//    //CargarCombo box 04
//    public void CargarComboBox04() {
//        //CARGANDO COMBOBOX DE MATERIAS
//        ArrayList arryRad = new ArrayList();
//        mate = new Materia();
//        arryRad = mate.MostrarMateriasPlan04();
//        JList list_rad = new JList();
//        DefaultListModel listModel_rad = new DefaultListModel();
//        listModel_rad.addElement("Seleccione");
//        if (arryRad != null) {
//            for (int i = 0; i < arryRad.size(); i++) {
//                entMate = (EntityMateria) arryRad.get(i);
//                listModel_rad.addElement(entMate.getCodigo_asignatura());
//            }
//        } else {
//            JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la tabla Materia", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
//        }
//        list_rad.setModel(listModel_rad);
//        this.jcmbMateria.setModel(new DefaultComboBoxModel(listModel_rad.toArray()));
//        this.jcmbMateria.setSelectedIndex(0);
//    }
    public void CargarcomboboxHorario() {
        ArrayList arry1 = new ArrayList();
        hora = new Horario();
        DefaultListModel List_Model = new DefaultListModel();
        JList list1 = new JList();

        arry1 = hora.MostrarCatalagoHorarios();
        List_Model.addElement("Seleccione");
        if (arry1 != null) {
            for (int i = 0; i < arry1.size(); i++) {
                entHora = (EntityHorario) arry1.get(i);
                List_Model.addElement(entHora.getHorario());
            }
        } else {
            JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la tabla Materia", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
        }
        list1.setModel(List_Model);
        this.jcmbHorario.setModel(new DefaultComboBoxModel(List_Model.toArray()));
        this.jcmbHorario.setSelectedIndex(0);
    }

    public void CargarComboBoxCatedratico() {
        ArrayList arry2 = new ArrayList();
        cate = new Catedratico();
        DefaultListModel List_Model2 = new DefaultListModel();
        JList list2 = new JList();
        arry2 = cate.MostrarCatedraticos();
        List_Model2.addElement("Seleccione");
        if (arry2 != null) {
            for (int i = 0; i < arry2.size(); i++) {
                entCate = (EntityCatedratico) arry2.get(i);
                List_Model2.addElement(entCate.getNombre().concat(" ").concat(entCate.getApellido()));
            }
        } else {
            JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la tabla Materia", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
        }
        list2.setModel(List_Model2);
        this.jcmbCatedratico.setModel(new DefaultComboBoxModel(List_Model2.toArray()));
        this.jcmbCatedratico.setSelectedIndex(0);
    }

    public void CargarComboGrupo() {
        ArrayList arry3 = new ArrayList();
        grupo = new Grupo();
        DefaultListModel List_Model3 = new DefaultListModel();
        JList list3 = new JList();
        arry3 = grupo.MostrarGrupos();
        List_Model3.addElement("Seleccione");
        if (arry3 != null) {
            for (int i = 0; i < arry3.size(); i++) {
                entGrupo = (EntityGrupo) arry3.get(i);
                List_Model3.addElement(entGrupo.getGrupo());
            }
        } else {
            JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la tabla Materia", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
        }
        list3.setModel(List_Model3);
        this.jcmbGrupo.setModel(new DefaultComboBoxModel(List_Model3.toArray()));
        this.jcmbGrupo.setSelectedIndex(0);
    }

    public frmMantenimientoGrupoLaboratorio() {
        initComponents();
        CargarcomboboxHorario();
        CargarComboBoxCatedratico();
        CargarComboGrupo();
        PopulatTabla();
        cargarComboboxPlan();
        this.setTitle("Nuevo grupo de Laboratorio");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtbleGrupos = new javax.swing.JTable();
        jSeparator1 = new javax.swing.JSeparator();
        jcmbGrupo = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jbtnCancelar = new javax.swing.JButton();
        jbtnAgregar = new javax.swing.JButton();
        jcmbCatedratico = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jcmbHorario = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jcmbPlan = new javax.swing.JComboBox();
        jcmbPlan2 = new javax.swing.JComboBox();
        jcmbMateria2 = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jcmbMateria = new javax.swing.JComboBox();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);

        jLabel1.setFont(new java.awt.Font("DejaVu Sans Condensed", 1, 18)); // NOI18N
        jLabel1.setText("Grupos de Laboratorio");

        jtbleGrupos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane2.setViewportView(jtbleGrupos);

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jcmbGrupo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcmbGrupo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcmbGrupoItemStateChanged(evt);
            }
        });

        jLabel5.setText("Grupo:");

        jbtnCancelar.setBackground(new java.awt.Color(202, 88, 92));
        jbtnCancelar.setText("Cancelar");
        jbtnCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbtnCancelarMouseClicked(evt);
            }
        });

        jbtnAgregar.setIcon(new javax.swing.ImageIcon("/home/mario/Dropbox/Sistema de laboratorio/Imagenes/agregar.jpg")); // NOI18N
        jbtnAgregar.setText("Agregar");
        jbtnAgregar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbtnAgregarMouseClicked(evt);
            }
        });

        jcmbCatedratico.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcmbCatedratico.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcmbCatedraticoItemStateChanged(evt);
            }
        });

        jLabel4.setText("Catedratico:");

        jcmbHorario.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcmbHorario.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcmbHorarioItemStateChanged(evt);
            }
        });

        jLabel3.setText("Horario:");

        jLabel2.setText("Materia:");

        jcmbPlan.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcmbPlan.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcmbPlanItemStateChanged(evt);
            }
        });

        jcmbPlan2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcmbPlan2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcmbPlan2ItemStateChanged(evt);
            }
        });

        jcmbMateria2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jcmbMateria2MouseClicked(evt);
            }
        });
        jcmbMateria2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcmbMateria2ItemStateChanged(evt);
            }
        });

        jLabel6.setText("Plan:");

        jcmbMateria.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcmbMateriaItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(90, 90, 90)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jcmbPlan, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jcmbPlan2, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jcmbMateria, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jcmbMateria2, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(jLabel2)
                                        .addGap(89, 89, 89))))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(174, 174, 174)
                                .addComponent(jLabel6)))
                        .addGap(86, 86, 86))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jbtnAgregar)
                                .addGap(18, 18, 18)
                                .addComponent(jbtnCancelar)
                                .addGap(23, 23, 23))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(84, 84, 84))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel5))
                                .addGap(43, 43, 43)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jcmbGrupo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGap(96, 96, 96))
                                    .addComponent(jcmbHorario, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jcmbCatedratico, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))))
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 524, Short.MAX_VALUE)
                .addGap(18, 18, 18))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(jLabel1)
                .addGap(34, 34, 34)
                .addComponent(jLabel6)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcmbPlan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jcmbPlan2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcmbMateria2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jcmbMateria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jcmbHorario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcmbCatedratico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jcmbGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnAgregar)
                    .addComponent(jbtnCancelar))
                .addGap(21, 21, 21))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnCancelarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbtnCancelarMouseClicked
        this.dispose();
    }//GEN-LAST:event_jbtnCancelarMouseClicked

    private void jbtnAgregarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbtnAgregarMouseClicked

        try {
            int id_materia1=this.id_materia1;
            int id_materia2=this.id_materia2;
            int id_horario = this.id_horario;
            int id_catedratico = this.id_catedratico;
            int id_grupo = this.id_grupo;



//            if (this.jcmbMateria.getSelectedItem().equals("IAF0/FIS1")) {

                detahorlab = new DetalleHorarioLab();
                String msj = detahorlab.InsertarGrupoLaboratorio(id_materia1,id_materia2,id_horario, id_catedratico, id_grupo);
//            String msj = detahorMat.InsertarNuevoHorarioMateria(id_materia, id_horario, id_catedratico, id_grupo);
                JOptionPane.showMessageDialog(rootPane, msj, "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
//            } else if (this.jcmbMateria.getSelectedItem().equals("FCA1/FIS2")) {
//                detahorlab = new DetalleHorarioLab();
//                String msj = detahorlab.InsertarFCA1_FIS2_Laboratorio(id_horario, id_catedratico, id_grupo);
//                JOptionPane.showMessageDialog(rootPane, msj, "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
//            } else if (this.jcmbMateria.getSelectedItem().equals("FCA2/FIS3")) {
//                detahorlab = new DetalleHorarioLab();
//                String msj = detahorlab.InsertarFCA2_FIS3_Laboratorio(id_horario, id_catedratico, id_grupo);
//                JOptionPane.showMessageDialog(rootPane, msj, "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
//            } else if (this.jcmbMateria.getSelectedItem().equals("FCA3/FIS4")) {
//                detahorlab = new DetalleHorarioLab();
//                String msj = detahorlab.InsertarFCA3_FIS4_Laboratorio(id_horario, id_catedratico, id_grupo);
//                JOptionPane.showMessageDialog(rootPane, msj, "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
//            }
            
            PopulatTabla();
        } catch (Exception ex) {
            System.out.println(ex.toString());
        }

    }//GEN-LAST:event_jbtnAgregarMouseClicked

    private void jcmbCatedraticoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcmbCatedraticoItemStateChanged
        ArrayList arryItem3 = new ArrayList();
        arryItem3 = cate.MostrarCatedraticos();
        if (arryItem3 != null) {
            for (int i = 0; i < arryItem3.size(); i++) {
                entCate = (EntityCatedratico) arryItem3.get(i);
                if (this.jcmbCatedratico.getSelectedItem().equals(entCate.getNombre().concat(" ").concat(entCate.getApellido()))) {
                    id_catedratico = entCate.getId();
                }
            }
        }
    }//GEN-LAST:event_jcmbCatedraticoItemStateChanged

    private void jcmbHorarioItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcmbHorarioItemStateChanged
        ArrayList arryItem2 = new ArrayList();
        arryItem2 = hora.MostrarCatalagoHorarios();
        if (arryItem2 != null) {
            for (int i = 0; i < arryItem2.size(); i++) {
                entHora = (EntityHorario) arryItem2.get(i);
                if (this.jcmbHorario.getSelectedItem().equals(entHora.getHorario())) {
                    id_horario = entHora.getId_horario();
                }
            }
        }
    }//GEN-LAST:event_jcmbHorarioItemStateChanged

    private void jcmbGrupoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcmbGrupoItemStateChanged
        ArrayList arryItem4 = new ArrayList();
        arryItem4 = grupo.MostrarGrupos();
        if (arryItem4 != null) {
            for (int i = 0; i < arryItem4.size(); i++) {
                entGrupo = (EntityGrupo) arryItem4.get(i);
                if (this.jcmbGrupo.getSelectedItem().equals(entGrupo.getGrupo())) {
                    id_grupo = entGrupo.getId_grupo();
                }
            }
        }
    }//GEN-LAST:event_jcmbGrupoItemStateChanged

    private void jcmbPlanItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcmbPlanItemStateChanged
        ArrayList arryPlan = new ArrayList();

        pla = new Plan();
        arryPlan = pla.MostrarPlan();

        for (int i = 0; i < arryPlan.size(); i++) {
            entPla = (EntityPlan) arryPlan.get(i);
            if (this.jcmbPlan.getSelectedItem().equals(entPla.getNombre_plan())) {
                this.id_plan = entPla.getId_plan();
            }
        }

        CargarComboBoxMateria(id_plan);
    }//GEN-LAST:event_jcmbPlanItemStateChanged

    private void jcmbPlan2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcmbPlan2ItemStateChanged
        ArrayList arryPlan = new ArrayList();

        pla = new Plan();
        arryPlan = pla.MostrarPlan();

        for (int i = 0; i < arryPlan.size(); i++) {
            entPla = (EntityPlan) arryPlan.get(i);
            if (this.jcmbPlan2.getSelectedItem().equals(entPla.getNombre_plan())) {
                this.id_plan2 = entPla.getId_plan();
            }
        }

        CargarComboBoxMateria2(id_plan2);
    }//GEN-LAST:event_jcmbPlan2ItemStateChanged

    private void jcmbMateria2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jcmbMateria2MouseClicked

    }//GEN-LAST:event_jcmbMateria2MouseClicked

    private void jcmbMateria2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcmbMateria2ItemStateChanged
        ArrayList arryMateria2 = new ArrayList();

        mate = new Materia();
        arryMateria2=mate.MostrarMateriasPlan_U1(id_plan2);

        for (int i = 0; i < arryMateria2.size(); i++) {
            entMate = (EntityMateria) arryMateria2.get(i);
            if (this.jcmbMateria2.getSelectedItem().equals(entMate.getCodigo_asignatura())) {
                this.id_materia2 = entMate.getId_materia();
            }
        }
    }//GEN-LAST:event_jcmbMateria2ItemStateChanged

    private void jcmbMateriaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcmbMateriaItemStateChanged
        ArrayList arryMateria = new ArrayList();

        mate = new Materia();
        arryMateria = mate.MostrarMateriasPlan_U1(id_plan);

        for (int i = 0; i < arryMateria.size(); i++) {
            entMate = (EntityMateria) arryMateria.get(i);
            if (this.jcmbMateria.getSelectedItem().equals(entMate.getCodigo_asignatura())) {
                this.id_materia1 = entMate.getId_materia();
            }
        }
    }//GEN-LAST:event_jcmbMateriaItemStateChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JButton jbtnAgregar;
    private javax.swing.JButton jbtnCancelar;
    private javax.swing.JComboBox jcmbCatedratico;
    private javax.swing.JComboBox jcmbGrupo;
    private javax.swing.JComboBox jcmbHorario;
    private javax.swing.JComboBox jcmbMateria;
    private javax.swing.JComboBox jcmbMateria2;
    private javax.swing.JComboBox jcmbPlan;
    private javax.swing.JComboBox jcmbPlan2;
    private javax.swing.JTable jtbleGrupos;
    // End of variables declaration//GEN-END:variables
}
